<template>
  <div class="app-container">
      
     <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="合约" prop="symbol">
          <el-input v-model="filterForm.symbol" clearable placeholder="合约" style="width: 200px;" class="filter-item" @input="handleFilter" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="周期" prop="scale">
          
      <el-radio-group v-model="filterForm.scale" @input="handleFilter">
        <el-radio-button label="15">M15</el-radio-button>
        <el-radio-button label="1440">D1</el-radio-button>
      </el-radio-group>
        </el-form-item>
      </el-form>
    <el-table
      key="realtimeList"
      v-loading="listLoading"
      :data="list"
      stripe
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="合约" width="200">
        <template slot-scope="{row}">
          <span >{{ row.symbol }}</span>
        </template>
      </el-table-column>
      <el-table-column label="日期" width="140">
        <template slot-scope="{row}">
          <span >{{ row.cycle }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开盘价" width="100">
        <template slot-scope="{row}">
          <span >{{ row.close }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最低价" width="100">
        <template slot-scope="{row}">
          <span >{{ row.low }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最高价" width="100">
        <template slot-scope="{row}">
          <span >{{ row.high }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收盘价" width="100">
        <template slot-scope="{row}">
          <span >{{ row.close }}</span>
        </template>
      </el-table-column>
      <el-table-column label="成交量" width="100">
        <template slot-scope="{row}">
          <span >{{ row.volume }}</span>
        </template>
      </el-table-column>
      <el-table-column label="成交额" width="100">
        <template slot-scope="{row}">
          <span >{{ row.amount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交时间">
        <template slot-scope="{row}">
          <span >{{ row.createdAt }}</span>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />

  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import { init,registerIndicator } from 'klinecharts'
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getQuotationList} from '@/api/knowledge/quotation' 
import {getSymbol} from '@/utils/symbol' // secondary package based on el-pagination

export default {
  name: 'faultinessAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      symbolList:[],
      documentationList:[],
      realtimeTimer:null,
      allowedLoaded:false,
      allowedLoadedRealtime:false,
      contractList: [
      ],
      total: 0,
      listLoading: false,
      connected:"loading",
      list:[],
      filterForm: {
        page: 1,
        size: 10,
        scale:1440,
        symbol:''
      }
    }
  },
  mounted(){
  },
  created() {
    //开启行情自动读取
    this.allowedLoaded = true;
    this.allowedLoadedRealtime = true;
    this.filterForm.symbol = this.$route.query && this.$route.query.symbol
    let symbolData = getSymbol()
    try {
      this.localSymbol = symbolData.code
    } catch (error) {
      
    }
    this.getList()
  },
  destroyed(){
  },
  methods: {
    getList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getQuotationList(_this.filterForm).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            _this.list = response.data.list
            _this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleRefreshButton:function(){
        this.getList()
    },
    handleDetail:function(item){
      this.filterForm.symbol = item.code;
      this.getRealtimeList()
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    }
  }
}
</script>
<style>

</style>